var _n69;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.XiaoMiHutui = undefined;
var $2ADManager = require("ADManager");
var $2ADInterface = require("ADInterface");
var $2XiaoMiConstant = require("XiaoMiConstant");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var d;
(function (e) {
  e[e.JiuGongGe = 0] = "JiuGongGe";
  e[e.HengFu = 1] = "HengFu";
  e[e.ChouTi = 2] = "ChouTi";
  e[e.XuanFuQiu = 3] = "XuanFuQiu";
})(d = exports.XiaoMiHutui || (exports.XiaoMiHutui = {}));
var def_XiaoMiAD = _n69 = /* */function (_o$default) {
  babel_inherits(n, _o$default);
  var _super101 = babel_createSuper(n);
  function n() {
    var _this236;
    babel_classCallCheck(this, n);
    _this236 = _super101.apply(this, arguments);
    _this236.videoCallBack = null;
    _this236.isShare = false;
    return _this236;
  }
  babel_createClass(n, [{
    key: "initAd",
    value: function initAd() {
      this.creatBanner();
      this.createVideo();
    }
  }, {
    key: "showNative",
    value: function showNative(e) {}
  }, {
    key: "hideNative",
    value: function hideNative() {}
  }, {
    key: "creatInsert",
    value: function creatInsert() {
      this.insertAd = qg.createInterstitialAd({
        adUnitId: $2XiaoMiConstant.default.POSID_InsertAD
      });
    }
  }, {
    key: "createVideo",
    value: function createVideo() {
      var _this237 = this;
      this.rewardVideoAd = qg.createRewardedVideoAd({
        adUnitId: $2XiaoMiConstant.default.POSID_VedioAD
      });
      this.rewardVideoAd.onError(function () {
        cc.audioEngine.resumeMusic();
        cc.director.resume();
      });
      this.rewardVideoAd.onClose(function (e) {
        if (e && e.isEnded || undefined === e) {
          cc.director.resume();
          _this237.videoCallBack && _this237.videoCallBack();
          _this237.showToast("奖励领取成功");
          cc.audioEngine.resumeMusic();
        } else {
          _this237.showToast("播放中途退出");
          cc.audioEngine.resumeMusic();
          cc.director.resume();
        }
      });
      this.rewardVideoAd.load();
    }
  }, {
    key: "showToast",
    value: function showToast(e) {
      qg.showToast({
        title: e
      });
    }
  }, {
    key: "showInsert",
    value: function showInsert() {
      var _this238 = this;
      if (!_n69.canShowInsertXiaoMi()) {
        return;
      }
      this.creatInsert();
      var e = this;
      this.insertAd.onLoad(function () {
        console.log("插屏广告加载成功");
        _this238.insertAd.show();
      });
      this.insertAd.onError(function () {
        if (e.insertAd) {
          try {
            e.insertAd.destroy();
          } catch (t) {}
        }
      });
      this.insertAd.onClose(function (t) {
        e.log("插屏广告关闭:" + t);
        if (e.insertAd) {
          try {
            e.insertAd.destroy();
          } catch (a) {}
        }
      });
    }
  }, {
    key: "showVideo",
    value: function showVideo(e) {
      var _this239 = this;
      if (null != this.rewardVideoAd && null != this.rewardVideoAd) {
        cc.audioEngine.pauseMusic();
        cc.director.pause();
        this.videoCallBack = e;
        this.rewardVideoAd.show().catch(function (e) {
          cc.audioEngine.resumeMusic();
          cc.director.resume();
          _n69.insertIntervalTime = new Date().getTime();
          _this239.rewardVideoAd.load().then(function () {
            _this239.rewardVideoAd.show().catch(function () {
              _this239.showToast("暂无广告");
            });
          }).catch(function () {
            _this239.showToast("暂无广告");
          });
          console.log("广告组件出现问题", e);
        });
        console.log("视频加载成功");
      } else {
        this.createVideo();
      }
    }
  }, {
    key: "creatBanner",
    value: function creatBanner() {
      var _this240 = this;
      this.bannerAd = qg.createBannerAd({
        adUnitId: $2XiaoMiConstant.default.POSID_BannerAD,
        adIntervals: 30
      });
      this.bannerAd.onError(function (e) {
        _this240.bannerAd = null;
        console.log("initBanner err:" + e);
      });
    }
  }, {
    key: "requestSubscribeSystemMessage",
    value: function requestSubscribeSystemMessage(e) {}
  }, {
    key: "onAddToFavorites",
    value: function onAddToFavorites() {}
  }, {
    key: "showBanner",
    value: function showBanner() {
      this.bannerAd || this.creatBanner();
      this.bannerAd.show().then(function () {
        console.log("banner加载成功");
      }).catch(function (e) {
        console.log("showBanner err:" + JSON.stringify(e));
      });
    }
  }, {
    key: "hideBanner",
    value: function hideBanner() {
      if (null != this.bannerAd) {
        this.bannerAd.hide();
        this.bannerAd = null;
      }
    }
  }, {
    key: "recorderStart",
    value: function recorderStart() {}
  }, {
    key: "recorderStop",
    value: function recorderStop() {}
  }, {
    key: "share",
    value: function share(e) {}
  }, {
    key: "canShare",
    value: function canShare() {
      return !(new Date().getTime() - this.shareTime < 3e3 || (this.shareTime = new Date().getTime(), 0));
    }
  }, {
    key: "addShortcut",
    value: function addShortcut() {}
  }, {
    key: "exitGame",
    value: function exitGame() {
      console.log("exit===");
      qg.exitApplication({
        success() {},
        fail() {
          console.log("fail===");
        },
        complete() {
          console.log("complete===");
        }
      });
    }
  }, {
    key: "log",
    value: function log(e) {
      console.log("WeChatAD:" + e);
    }
  }], [{
    key: "showHuTuiAd",
    value: function showHuTuiAd(e) {
      $2ADManager.default.instance.isTest || qg.displayAd({
        type: this.HutuiType[e],
        upid: $2XiaoMiConstant.default.POSID_HuTuiAD[e],
        success(e) {
          console.log(e);
        },
        fail(t) {
          e == d.JiuGongGe && qg.showToast({
            title: "暂无广告"
          });
          console.log(t);
        }
      });
    }
  }, {
    key: "closeHuTuiAd",
    value: function closeHuTuiAd(e) {
      if (!$2ADManager.default.instance.isTest) {
        try {
          if (!qg.closeAd) {
            return;
          }
          qg.closeAd({
            type: this.HutuiType[e],
            success(e) {
              console.log(e);
            },
            fail(e) {
              console.log(e);
            }
          });
        } catch (t) {}
      }
    }
  }, {
    key: "canShowInsertXiaoMi",
    value: function canShowInsertXiaoMi() {
      if (new Date().getTime() - this.insertIntervalTime < 3e4) {
        return console.log("插屏显示间隔时间不足"), false;
      } else {
        return console.log("可以显示插屏"), this.insertIntervalTime = new Date().getTime(), true;
      }
    }
  }]);
  return n;
}($2ADInterface.default);
def_XiaoMiAD.insertIntervalTime = 0;
def_XiaoMiAD.isSubscribe = false;
def_XiaoMiAD.HutuiType = [100, 120, 130, 150];
def_XiaoMiAD = _n69 = cc__decorate([ccp_ccclass], def_XiaoMiAD);
exports.default = def_XiaoMiAD;